package com.qdu.study_app.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.qdu.study_app.R;
import com.qdu.study_app.bean.Clock;

import java.util.Random;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.datatype.BmobRelation;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class Activity_new_clock extends AppCompatActivity {


    private FloatingActionButton startTask;
    private SeekBar progress;
    private EditText task_title;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_clock);

    }

    @Override
    protected void onStart() {
        super.onStart();
        init();

    }
    private void init(){
        startTask = findViewById(R.id.start_clock);
        startTask.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                progress = findViewById(R.id.seek_time_length);
                task_title = findViewById(R.id.new_clock_title);
                // 0-9的随机数
                Random random = new Random();
                String s_task_title = task_title.getText().toString();
                long time = progress.getProgress();
                BmobRelation relation = new BmobRelation();
                relation.add(BmobUser.getCurrentUser());

                Clock clock = new Clock();
                clock.setTime(time);
                clock.setTask_name(s_task_title);
                clock.setImg_index(random.nextInt(10));
                clock.setUser(relation);
                clock.save(new SaveListener<String>() {
                    @Override
                    public void done(String s, BmobException e) {
                        if(e == null){
                            finish();
                            System.out.println("1:--------------"+s_task_title);
                        }
                        else {
                            System.out.println("00---------------------"+e);
                        }

                    }
                });
            }
        });
    }
}